clear 
clear all
cap log close
log using ..\output\logfiles\graph_1A_1B.smcl, replace

************ Figures

use  ..\temp\trade_data_h6_covars_h1.dta, clear
set scheme s1mono
rename tf_best_adv tf

gen B1_hs6_ln = ln(B1_hs6)
bys c y: egen v_tot = total(v)
gen share_weight = v/v_tot

gen B1_hs6_ln_weight = B1_hs6_ln*share_weight
drop if B1_hs6_ln_weight==.

gen ntm_weight = ntm_EF*share_weight

collapse (mean) commodity_exports_orig B1_hs6 B1_hs6_ln tariff_wdi  ntm_EF (sum) B1_hs6_ln_weight ntm_weight, by(c y) 

collapse (mean) commodity_exports_orig B1_hs6_ln_weight  tariff_wdi ntm_weight ntm_EF , by(c) 

*Import concentration
loc run = 1
if `run' == 1{
regress B1_hs6_ln_weight commodity_export, r
twoway (scatter B1_hs6_ln_weight commodity_export, mstyle(none) mlabel(c))  (lfit B1_hs6_ln_weight commodity_export) , legend(off) xtitle("Commodity export share of total merchandise exports") ytitle("Average HHI of country's import markets") graphregion(color(white)) ylabel(6.9077553 "1000" 7.6009025 "2000" 8.0063676 "3000") plotregion( lcolor(white))
graph export ..\output\Graph_1A_alt.png, as(png) replace
graph export ..\output\Graph_1A_alt.pdf, as(pdf) replace
}

*Trade protection
loc run = 1
if `run' == 1{
replace tariff_wdi = tariff_wdi/100
regress tariff_wdi  commodity_export, r
twoway (scatter tariff_wdi commodity_export, mstyle(none) mlabel(c))  (lfit tariff_wdi  commodity_export) , legend(off) ytitle("Tariff rate, applied, weighted mean, all products") xtitle("Commodity export share of total merchandise exports") graphregion(color(white))  plotregion( lcolor(white))
graph export ..\output\Graph_1B_alt.png, as(png) replace
graph export ..\output\Graph_1B_alt.pdf, as(pdf) replace
}




log close